package com.keeping.aiimagery.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.keeping.aiimagery.entity.MsgVO;
import com.keeping.aiimagery.handler.strategy.MessageStrategy;
import com.unfbx.chatgpt.OpenAiStreamClient;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.websocket.Session;

/**
 * 次数不足消息策略
 */
@Component
public class InsufficientStrategy implements MessageStrategy {

    private static OpenAiStreamClient openAiStreamClient;

    @Autowired
    public void setOrderService(OpenAiStreamClient openAiStreamClient) {
        this.openAiStreamClient = openAiStreamClient;
    }

    public InsufficientStrategy() {
    }

    @SneakyThrows
    @Override
    public void sendText(Session session, String userId, String roomId, String msg) {
        ObjectMapper mapper = new ObjectMapper();
        String text = "您好，您的剩余次数不足，您可以选择【充值】或者【邀请他人】增加使用次数，感谢使用！";
        String delta = mapper.writeValueAsString(MsgVO.builder().content(text).isEnd(true).roomId(roomId).uid(userId).build());
        session.getBasicRemote().sendText(delta);
    }
}
